<meta meta="淘宝联盟" args="data"/>
<style>

</style>
<div class="row">
	<div class="col-md-8">
		<form class="form-horizontal" id="form" s="form,datac,nda,valid" s-data="data" style="width: 600px;">
			<div class="form-group">
				<label class="col-sm-3 control-label">unionId</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="unionId" placeholder="unionId"
								 s-valid-error="require()"/>
				</div>
			</div>
			<!--<div class="form-group">-->
				<!--<label class="col-sm-3 control-label">siteId</label>-->
				<!--<div class="col-sm-9">-->
					<!--<input autocomplete="off" type="text" class="form-control" name="siteId" placeholder="siteId"-->
								 <!--s-valid-error="require()"/>-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">
				<label class="col-sm-3 control-label">AdzoneId</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="adzoneId" placeholder="AdzoneId"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">站点ID</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="siteId" placeholder="站点ID"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">PID</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="pid" placeholder="PID"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">默认用户PID</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="defaultUserPid" placeholder="默认用户PID"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">会员运营PID</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="rebatePid" placeholder="会员运营PID"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">会员邀请码</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" id="inviteCode" name="inviteCode" readonly placeholder="会员邀请码"
								 s-valid-error="require()"/>
					<input type="button" class="btn btn-info btn-outline btn-sm" value="获取会员邀请码" s-click="genInviteCode(3, $inviteCode)" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">渠道邀请码</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" id="channelInviteCode" name="channelInviteCode" readonly placeholder="渠道邀请码"
								 s-valid-error="require()"/>
					<input type="button" class="btn btn-info btn-outline btn-sm" value="获取渠道邀请码" s-click="genInviteCode(1, $channelInviteCode)" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">会员运营AdzoneId</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="rebateAdzoneId" placeholder="会员运营AdzoneId"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">渠道PID</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="proxyPid" placeholder="渠道PID"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">渠道AdzoneId</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="proxyAdzoneId" placeholder="渠道AdzoneId"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">淘宝联盟账号</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" name="taobaoAccount" placeholder="淘宝联盟账号"
								 s-valid-error="require()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">淘宝联盟账号Id</label>
				<div class="col-sm-9">
					<input autocomplete="off" type="text" class="form-control" placeholder="淘宝联盟账号ID" name="taobaoAccountId"
								 s-valid-error="require(),number(1)"/>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript">
	S.getContent = function () {
		var deferred = $.Deferred();
		$form.validate().done(function () {
			deferred.resolve(Smart.serializeToObject($form.node))
		})
		return deferred;
	}

	function test() {
		S.post("/api/taobao-union/test-connection-with-login").done(function (rs) {
			if (rs.success) {
				S.alert("测试成功")
			} else {
				if (rs.redirectUrl) {
					S.alert("测试失败，需要验证登录，请点击链接进行登录验证<a href='" + rs.redirectUrl + "' style='word-break: break-all' external target='_blank'>" + rs.redirectUrl + "</a>")
				}
			}
		})
	}

	function genInviteCode(codeType, $inviteCode) {
		S.get('/api/tbk-api/invite-code', {codeType: codeType}).done(function(rs) {
			$inviteCode.node.val(rs.inviterCode)
		})
	}
</script>